GuiManager = {}
GuiManager.mt = { __index = GuiManager }
setmetatable(GuiManager, GuiManager.mt)

function GuiManager:initialize()
	

	
	self.popups = {}
	


	
end


function GuiManager.new()

	local o = GuiManager.initialize()

	return o

end

function GuiManager:remove_popup( id )

	self.popups[id]:destroy()

	table.remove(self.popups, id)

end

function GuiManager:new_popup(type, x, y, w, h, text)

	if not type then print("ERROR: GUIManager NEW_POPUP type is NIL"); return nil end
	
	local pop = self:translate_type(type)
	
	if x and y then pop:setPos(x,y) else print("ERROR: NEW_POPUP no x or y"); return nil end
	if h and w then pop:setDim(w, h) else print("ERROR: NEW_POPUP no w or h"); return nil end
	
	if text then pop:setText(text) end	
	
	local p = GuiManager.get_popup_amount(self)
	
	local iter = p+1
	
	self.popups[iter] = pop
	
	return self.popups[iter], iter
	

end

function GuiManager:translate_type(type)
	types = {
		["label"] = function() return gui:createLabel() end,
		["button"] = function() return gui:createButton() end,
		["image"] = function() return gui:createImage() end,
		["checkbox"] = function() return gui:createCheckBox() end,
		["radio"] = function() return gui:createRadioButton() end,
		["window"] = function() return gui:createWindow() end,
		["editbox"] = function() return gui:createEditBox() end,
		["hslider"] = function() return gui:createHorzSlider() end,
		["vslider"] = function() return gui:createVertSlider() end,
		["textbox"] = function() return gui:createTextBox() end,
	
	}
	
	if not type then print("ERROR: GUIManager TRANSLATE_TYPE type is NIL"); return nil end
	
	if not types[type] then print("ERROR: GUIManager TRANSLATE_TYPE type NOT FOUND"); return nil end
	
	local o = types[type]()
	
	return o

end

function GuiManager:get_popups()

	return self.popups

end

function GuiManager:get_popup_amount()

	
	local o = self.popups
	local op 
	
	if not #o then op = 0 else op = #o end
	

	return op
	
end



return GuiManager